const qs = require("querystring");

//自定义中间件
let bodyParser = {
  urlencoded: function () {
    return function (req, res, next) {
      //通过原生的nodejs接受post参数 携带在req.body上
      let str = "";
      req.on("data", (chunk) => {
        str += chunk;
      });
      req.on("end", () => {
        console.log("??", str);
        let obj = qs.parse(str);
        console.log(obj);
        req.body = obj;
        next();
      });
    };
  },
};
module.exports = bodyParser;
